/* @(#)GSOrderDetailModifyConfirmAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-2-27     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import system.LoginContext;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.business.GSUniteGwProcessor;
import com.hitrust.gs.form.GSOrderDetailModifyForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSOrderDetailModifyVO;

/**
 * 巴士物资级订单明细调整保存
 */
public class GSBusOrderDetailModifyConfirmAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        //为了在保存调整信息后执行查询，所以调用GSOrderDetailModifyQueryForm
        GSOrderDetailModifyForm tForm = (GSOrderDetailModifyForm)aForm;
        ArrayList tList = new ArrayList();
        if(tForm.orderDetailIds2 != null && tForm.orderDetailIds2.length > 0){
            //取得当前操作员信息
            LoginContext context = (LoginContext)tForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            for(int i=0; i<tForm.orderDetailIds2.length; i++){
                GSOrderDetailModifyVO tOrderDetlModVO = new GSOrderDetailModifyVO();
                GSOrderDetailBean tOrderDetailBean = new GSOrderDetailBean();
                tOrderDetlModVO.orderDetailId = tForm.orderDetailIds2[i];
                String[] temp = tForm.provManufInfos2[i].split("-");
                tOrderDetlModVO.providerId = temp[0];
                tOrderDetlModVO.manufId = temp[1];
                tOrderDetlModVO.goodsUnitprice = Double.parseDouble(temp[2]);
                tOrderDetlModVO.mode=temp[3];
                tOrderDetlModVO.orderCount = tForm.orderCounts2[i];
                tOrderDetlModVO.orderDetailStatus = tForm.orderDtlStatus2[i];
                String tDate = "";
                //信息调整
                if(tForm.deliverGoodsDates2[i] != null && tForm.deliverGoodsDates2[i].length() == 10){
                    tDate = tForm.deliverGoodsDates2[i].substring(0,4) + "-" + tForm.deliverGoodsDates2[i].substring(5,7) + "-" + tForm.deliverGoodsDates2[i].substring(8);
                }
                tOrderDetlModVO.deliverGoodsDate = tDate;
                tOrderDetlModVO.deliverGoodsTime = tForm.deliverGoodsTimes2[i];
                tOrderDetlModVO.lastModifyId = context.getLoginUserId();
                tOrderDetlModVO.lastModifyContent = "更新订单信息";
                tOrderDetlModVO.isTradeFlatManuf = tForm.isTradeFlatManuf2[i];
                tOrderDetlModVO.isTradFlatProvider = tForm.isTradeFlatProvider2[i];
                tOrderDetlModVO.sign = tForm.sign2[i];
                tList.add(tOrderDetlModVO);
            }
            try{
                GSOrderProcessor tOrderProc = new GSOrderProcessor();
                //执行信息调整保存
                String msg = tOrderProc.updateOrderDetail(tList,context);
                tForm.getRequest().setAttribute("message",msg);
                //取得当前操作员可查询的订货单位和送货地址
                GSUniteGwProcessor unitePro=new GSUniteGwProcessor();
                aForm.getRequest().setAttribute("orderdept",unitePro.getWareHouseLevelName(context.getLoginWarehouseCode(), context.getLoginWarehouseCode()));
                //取得产品分类
                GSManufactureProcessor tManufProc = new GSManufactureProcessor();
                tManufProc.getManufactureOfLevel(aForm);
                aForm.getRequest().setAttribute("requery","true");
//                GSBusOrderDetailModifyQueryAction tOrdDtlModQryActon = new GSBusOrderDetailModifyQueryAction();
                return GSBaseConstants.FORWARD_SUCCESS;
//                return tOrdDtlModQryActon.execute(tForm);
            }catch(Exception e){
                tForm.getRequest().setAttribute("action","A150601.do");
                throw e;
            }
        }else{
            tForm.getRequest().setAttribute("action","A150601.do");
            throw new GSException(GSException.E00003,GSException.E00003_MSG);
        }
    }

}
